// components/titleHd/titleHd.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    itemDate:String ,
    username:String,
    currentTab:String,
    statistics:String,
    statistics:{
      type:Object,
      value:''
    },
    itemDate:String,
    showModalStatus:{type:Boolean}
       
  },

  /**
   * 组件的初始数据
   */
  data: {
    currentTab: 0,
    billList: [{ id: 0, name: '日账单' }, { id: 1, name: '月账单' }, { id: 2, name: '年账单' }], //账单类型 
    fields: 'day',
    orderType: 0,
    showModalStatus:false,
    billId: '0',
    size:10,
    paymentList: [
      {
        id: 0,
        value: '全部'
      }, {
        id: 1,
        value: '微信'
      }, {
        id: 2,
        value: '支付宝'
      }, {
        id: 3,
        value: '会员支付'
      }, {
        id: 4,
        value: '通用通'
      }],
    params:[],
  },

  /**
   * 组件的方法列表
   */
  methods: {
    _swichNav: function (e) {
      let t = this
      if (e.currentTarget.dataset.current == 1) {
        let index = t.data.index += 1
        t.setData({
          index
        })
      } else {
        t.setData({
          index: 0
        })
      }
      if (t.data.index > 1) {
        t.setData({
          isShow: false,
          currentTab: '2'
        })
      } else {
        t.setData({
          currentTab: e.currentTarget.dataset.current
        })
      }

    },
    _clickme() {
      this._showModal();
    },
    //隐藏对话框
    _hideModal: function () {
      // 隐藏遮罩层
      var animation = wx.createAnimation({
        duration: 200,
        timingFunction: "linear",
        delay: 0
      })
      this.animation = animation
      animation.translateY(300).step()
      this.setData({
        animationData: animation.export(),
      })
      setTimeout(function () {
        animation.translateY(0).step()
        this.setData({
          animationData: animation.export(),
          showModalStatus: false
        })
      }.bind(this), 200)
    },

     // 显示遮罩层
    _showModal() {
      var animation = wx.createAnimation({
        duration: 200,
        timingFunction: "linear",
        delay: 0
      })
      this.animation = animation
      //在 Y 轴平移的距离
      animation.translateY(300).step()
      this.setData({
        //动画实例的export方法导出动画数据传递给组件的animation属性
        animationData: animation.export(),
        showModalStatus: true
      })
      setTimeout(function () {
        animation.translateY(0).step()
        this.setData({
          animationData: animation.export()
        })
      }.bind(this), 200)
    },
    
    _billClik(e) {
      let t = this
      let billId = e.currentTarget.dataset.id;
      let { currentDate, currentMonth, currentYear } = t.data
      if (billId == 0) { //日账单
        t.setData({
          showTime: true,
          fields: 'day',
          itemDate: currentDate
        })
      } else if (billId == 1) {
        t.setData({
          showTime: true,
          fields: 'month',
          itemDate: currentMonth
        })
      } else {
        t.setData({
          showTime: true,
          fields: 'year',
          itemDate: currentYear
        })
      }
      this.setData({
        billId
      })
    },
    //账单类型
    _pickerTimeShow(e) {
      this.setData({
        itemDate: e.detail.value
      })
    },
    //退出登录
    _exitLogin() {
      wx.showModal({
        title: '提示',
        content: '是否切换账号？',
        success(res) {
          if (res.confirm) {
            wx.reLaunch({
              url: '../index/index'
            })
          }
        }
      })

    },
    //支付类型
    _paymentClik(e) {
      let orderType = e.currentTarget.dataset.id;
      let value = e.currentTarget.dataset.value;
      this.setData({
        orderType
      })
  
    },

    // --点击查询---
    _filtrateClik() {
      let t = this
      let {
        date,
        endDate,
        orderType, //支付类型
        billId,
        itemDate
      } = t.data

      let params = {
        quertType: billId,//账单类型
        orderType,//支付类型
        queryTime: itemDate, //具体时间
      }
      t.setData({
        params,
      })
      this.triggerEvent('myevent', {params})
      // t.transaction(page, size, params)

    },
  },

  lifetimes: {
    attached: function () {
      let myData = new Date();
      let getFullYear = myData.getFullYear();
      let getMonth = myData.getMonth() + 1;
      let getDate = myData.getDate();
      if (getDate < 10) {
        getDate = '0' + getDate
      }
      if (getMonth < 10) {
        getMonth = '0' + getMonth
      }
      let currentDate = getFullYear + '-' + getMonth + '-' + getDate; //年月日
      let currentMonth = getFullYear + '-' + getMonth  //年月
      let currentYear = getFullYear //年
      // 在组件实例进入页面节点树时执行
      this.setData({
        date: currentDate,
        endDate: currentDate,
        username: wx.getStorageSync("username"),
  
        itemDate: currentDate,
        currentMonth,
        currentYear,
        currentDate,
    
      })
    },
   
  },
 
})
